package com.megaspacevr.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 密码工具类
 */
public class PasswordUtil {
    
    private static final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    
    /**
     * 加密密码
     */
    public static String encode(String rawPassword) {
        return encoder.encode(rawPassword);
    }
    
    /**
     * 验证密码
     */
    public static boolean matches(String rawPassword, String encodedPassword) {
        return encoder.matches(rawPassword, encodedPassword);
    }
    
    /**
     * 测试方法 - 可以用来验证密码
     */
    public static void main(String[] args) {
        String password = "admin123";
        String encoded = "$2a$10$7JB720yubVSeLan6Zzg2XO8W1l0wJlS2Q2HHMb4ZLWt7Uef.Lsc.i";
        
        System.out.println("原密码: " + password);
        System.out.println("加密密码: " + encoded);
        System.out.println("验证结果: " + matches(password, encoded));
        
        // 生成新的加密密码
        System.out.println("新加密密码: " + encode(password));
    }
} 